<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>第二个网页</title>


    <!-- 引入 layui.css -->

    <link th:href="@{/css/layui.css}" rel="stylesheet"/>
    <!-- 引入 layui.js -->
<!--    <script src="layui.js"/>-->
    <script th:src="@{/layui.js}"></script>



    <style>

        .form_one{
            margin: 0 auto;
            max-width: 500px;
        }



    </style>

</head>


<body>



<div class="layui-container">

    <div class="layui-row">

        <div class="layui-col-md3">

        </div>

        <div class="layui-col-md6 form_one" >


            <form class="layui-form" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">书本名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="bookName" required  lay-verify="required" placeholder="请输入书本名称" autocomplete="off" class="layui-input">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">书本作者：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="authName" required lay-verify="required" placeholder="请输入书本作者" autocomplete="off" class="layui-input">
                    </div>

                </div>



                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>




        </div>
        <div class="layui-col-md3">

        </div>
    </div>


</div>





<script>
    //Demo

    layui.use(['jquery','form'], function(){
        var form = layui.form;
        var $ = layui.jquery;

        //监听提交
        form.on('submit(formDemo)', function(data){
            // layer.msg(JSON.stringify(data.field));

            // $.post("/demo01/insertBook", data.field,function (res){
            //
            //     layer.msg(JSON.stringify(res));
            // })

        var param = data.field ;

            // debugger ;

            $.ajax({
                //提交数据的类型 POST GET
                type:"POST",
                //提交的网址
                url:"/demo01/insertBook",
                //提交的数据
                data:JSON.stringify(param),

                //返回数据的格式
                datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
                headers:{'Content-Type':'application/json;charset=utf8','organId':'1333333333'},
                //在请求之前调用的函数
                // beforeSend:function(){$("#msg").html("logining");},
                //成功返回之后调用的函数
                success:function(data){


                    layer.msg(JSON.stringify(data));

                }   ,


                //调用出错执行的函数
                error: function(){
                    //请求出错处理

                }
            });



            return false;
        });
    });
</script>









</body>
</html>